package com.lgmshare.k3.controller;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.lgmshare.k3.ui.webview.WebViewActivity;

/**
 * @author lim
 * @description: TODO
 * @email lgmshare@gmail.com
 * @datetime 2017/11/15 10:12
 */
public class AppController {

    /**
     * 在应用内开发一个web页面
     *
     * @param context
     * @param stringTitleId
     * @param url
     */
    public static void startWebActivity(Context context, int stringTitleId, String url) {
        Intent intent = new Intent(context, WebViewActivity.class);
        intent.putExtra(WebViewActivity.EXTRA_WEB_TITLE, context.getString(stringTitleId));
        intent.putExtra(WebViewActivity.EXTRA_WEB_URL, url);
        context.startActivity(intent);
    }

    /**
     * 在外部浏览器打开web页面
     *
     * @param context
     * @param url
     */
    public static void startExternalWebActivity(Context context, String url) {
        Uri uri = Uri.parse(url);
        Intent it = new Intent(Intent.ACTION_VIEW, uri);
        context.startActivity(it);
    }

    /**
     * 发送本地广播
     *
     * @param context
     * @param action
     */
    public static void sendLocalBroadcast(Context context, String action) {
        Intent intent = new Intent();
        intent.setAction(action);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

    /**
     * 发送广播
     *
     * @param context
     * @param action
     */
    public static void sendBroadcast(Context context, String action) {
        Intent intent = new Intent();
        intent.setAction(action);
        context.sendBroadcast(intent);
    }

}
